package sk.tuke.serviceImpl;

import javax.ws.rs.core.Response;

import sk.tuke.domain.CommonOutput;
import sk.tuke.domain.Error;

public class CommonService {

	protected Response handleException(Class<?> clazz, Exception e, Response.Status status) throws InstantiationException, IllegalAccessException {
		CommonOutput o = new CommonOutput();
		o = o.getClass().cast(clazz.newInstance());
		String errorMessage = e.getMessage();
		long errorId = System.currentTimeMillis();
		if (errorMessage == null || errorMessage.equals("")) {
			errorMessage = "Server error, please contact system administrator and provide id [" + errorId + "]";
		}
		System.err.println(errorMessage);
		e.printStackTrace();
		Error error = new Error();
		error.setErrorType(e.getClass().getCanonicalName());
		error.setErrorMessage(errorMessage);
		o.setError(error);
		return Response.status(status).entity(o).build();
	}

}
